package server;

import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.UnknownHostException;
import server.gui.ServerGUI;
import shared.plugin.event.EventManager;


public class TestingServer {
    public ConnectionManager connectionManager;
    public EventManager eventManager;
    public StyleManager styleManager;
    public ServerSocket serverSocket;
    public PacketHandler packetHandler;
    public ServerGUI serverGUI;
    public int serverPort;

    public static void main(String[] args) {
        TestingServer server = new TestingServer();
        server.run();
    }

    public TestingServer(){
        packetHandler = new PacketHandler(this);
        serverPort = 32001;
        serverGUI = new ServerGUI(this);
        serverGUI.setVisible(true);
        serverGUI.addLine("TestingServer Started.");
        eventManager = new EventManager(this);
        connectionManager = new ConnectionManager(this);
        styleManager = new StyleManager(this);
    }

    protected void run(){
        try {
            serverSocket = new ServerSocket(serverPort, 10);
            serverGUI.addLine("ServerSocket created.");
            serverGUI.addLine("Current address " + InetAddress.getLocalHost().getHostAddress() + ":" + serverPort);
            AcceptConnectionThread accept = new AcceptConnectionThread(this);
            accept.start();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}